﻿namespace GSC.WebControls
{
    using System;
    using System.Collections.Generic;
    using System.Web.UI.Design;
    using System.Web.UI.Design.WebControls;
    using System.ComponentModel;
    using System.Web.UI;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.IO;
    using System.ComponentModel.Design;
    using System.Web.UI.HtmlControls;
    /// <summary>
    /// 
    /// </summary>
    class BackgroundCenterHeadControlDesigner : CompositeControlDesigner
    {
        private BackgroundCenterHeadControl _CenterHead;

        public override TemplateGroupCollection TemplateGroups
        {
            get
            {
                TemplateGroupCollection collection = new TemplateGroupCollection();
                TemplateGroup group;
                TemplateDefinition template;
                BackgroundCenterHeadControl control;
                control = (BackgroundCenterHeadControl)Component;
                //
                group = new TemplateGroup("Left");
                template = new TemplateDefinition(this, "LeftCellTemplate", control, "LeftCellTemplate", false);
                group.AddTemplateDefinition(template);
                collection.Add(group);
                group = new TemplateGroup("Center");
                template = new TemplateDefinition(this, "CenterCellTemplate", control, "CenterCellTemplate", false);
                group.AddTemplateDefinition(template);
                collection.Add(group);
                return collection;
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="Component"></param>
        public override void Initialize(IComponent Component)
        {
            base.Initialize(Component);
            this._CenterHead = (BackgroundCenterHeadControl)Component;
            SetViewFlags(ViewFlags.DesignTimeHtmlRequiresLoadComplete, true);
            this.SetViewFlags(ViewFlags.TemplateEditing, true);
        }
        /*
        /// <summary>
        /// </summary>
        /// <returns></returns>
        public override string GetDesignTimeHtml()
        {
            try
            {
                StringWriter sw = new StringWriter();
                HtmlTextWriter hw = new HtmlTextWriter(sw);
                this.CreateChildControls();
                Panel panel = new Panel();
                Table table = new Table();
                table.CellPadding = 0;
                table.CellSpacing = 0;
                table.BorderWidth = Unit.Pixel(0);
                table.BackColor = _CenterHead.BackColor;
                table.BorderColor = _CenterHead.BorderColor;
                table.BorderStyle = _CenterHead.BorderStyle;
                table.BorderWidth = _CenterHead.BorderWidth;
                table.Width = _CenterHead.Width;
                table.Height = _CenterHead.Height;
                table.Style["table-layout"] = "fixed";
                table.Style["overflow"] = "hidden";
                panel.Controls.Add(table);
                TableRow row = new TableRow();
                table.Rows.Add(row);
                //
                TableCell LeftCell = new TableCell();
                LeftCell.Height = _CenterHead.Height;
                LeftCell.Width = _CenterHead.LeftCellWidth;
                LeftCell.Style["overflow"] = "hidden";
                LeftCell.Style["background-position"] = "left top";
                if (string.IsNullOrEmpty(_CenterHead.LeftCellBackImage))
                    LeftCell.Style["background-image"] = "url(" + _CenterHead.ResolveClientUrl(_CenterHead.GetWebResourceUrl("Left.gif")) + ")";
                else
                    LeftCell.Style["background-image"] = "url(" + _CenterHead.ResolveClientUrl(_CenterHead.LeftCellBackImage) + ")";
                row.Cells.Add(LeftCell);
                foreach (Control item in _CenterHead.LeftCell.Controls)
                {
                    LeftCell.Controls.Add(item);
                }
                //
                TableCell CenterCell = new TableCell();
                CenterCell.Height = _CenterHead.Height;
                if (_CenterHead.CenterCellWidth.IsEmpty)
                    CenterCell.Style["width"] = "auto";
                else
                    CenterCell.Width = _CenterHead.CenterCellWidth;
                CenterCell.Style["overflow"] = "hidden";
                CenterCell.Style["background-position"] = "left top";
                if (string.IsNullOrEmpty(_CenterHead.CenterCellBackImage))
                    CenterCell.Style["background-image"] = "url(" + _CenterHead.ResolveClientUrl(_CenterHead.GetWebResourceUrl("Center.gif")) + ")";
                else
                    CenterCell.Style["background-image"] = "url(" + _CenterHead.ResolveClientUrl(_CenterHead.CenterCellBackImage) + ")";
                row.Cells.Add(CenterCell);
                foreach (Control item in _CenterHead.CenterCell.Controls)
                {
                    CenterCell.Controls.Add(item);
                }
                //
                TableCell RightCell = new TableCell();
                RightCell.Height = _CenterHead.Height;
                RightCell.Width = _CenterHead.RightCellWidth;
                RightCell.Style["overflow"] = "hidden";
                RightCell.Style["background-position"] = "left top";
                if (string.IsNullOrEmpty(_CenterHead.RightCellBackImage))
                    RightCell.Style["background-image"] = "url(" + _CenterHead.ResolveClientUrl(_CenterHead.GetWebResourceUrl("Right.gif")) + ")";
                else
                    RightCell.Style["background-image"] = "url(" + _CenterHead.ResolveClientUrl(_CenterHead.RightCellBackImage) + ")";
                row.Cells.Add(RightCell);
                panel.RenderControl(hw);
                return sw.ToString();
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
         */ 
    }
}